package com.jd.basic.controller;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;

@RestController
@RequestMapping("/email")
public class EmailController {
        @Autowired
        private JavaMailSender javaMailSender;
        @GetMapping("/pass")
        @ApiOperation(value = "邮箱注册")
        public void send2() throws MessagingException {
            //创建复杂邮件对象
            MimeMessage mimeMessage = javaMailSender.createMimeMessage();
            //发送复杂邮件的工具类
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true,"utf-8");
            helper.setFrom("461561986@qq.com");
            helper.setSubject("店铺激活邮件");
            helper.setText("<h1>你的店铺已经注册!!!</h1><img src='http://115.159.88.63:8800/group1/M00/00/10/rBEACmKYYHmARQX4AAFKgkkrvjA016.JPG' >" +
                    "</br>"+
                    "<a href='http://localhost:8080/shop/active/22'>点击该链接激活</a>",true);

            //添加附件
            helper.addAttachment("IMG_5140.JPG",new File("D:\\resources\\IMG_5140.JPG"));
            //收件人
            helper.setTo("2335318805@qq.com");
            javaMailSender.send(mimeMessage);
        }
}
